package com.example.riskmanage.service.impl;

import com.alibaba.fastjson.JSON;
import com.example.riskmanage.bean.Project;
import com.example.riskmanage.dao.ProjectDao;
import com.example.riskmanage.service.ProjectManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.HashMap;
import java.util.List;

@Service
public class ProjectManagerImpl implements ProjectManager {

    @Autowired
    ProjectDao projectDao;

    @Override
    public String getProjectService(Integer uid) {
        HashMap<String, Object> map = new HashMap<>();
        //1.调用dao层接口获取数据
        List<Project> projectList = projectDao.findAllByUid(uid);
        //2.将处理的数据封装到map
        map.put("projectList", projectList);
        map.put("flag",true);
        String respJSON = JSON.toJSONString(map);
        return respJSON;
    }

    public String addProjectService(Project project) {
        projectDao.save(project);
        return "ok";
    }

    @Override
    public String deleteProjectService(Integer id) {
        projectDao.deleteById(id);
        return "ok";
    }

    @Override
    public String geteditService(Integer id) {
        HashMap<String,Object> maps = new HashMap<>();
        //1.调用dao层接口获取数据
        Project edit=projectDao.findProjectById(id);
        //2.将处理的数据封装到map
        String respJSON = JSON.toJSONString(edit);
        return respJSON;
    }

    @Override
    public String editProjectService(Project project) {
        projectDao.save(project);
        return "ok";
    }

}
